//
//  ActivityDetailView.m
//  newDouban
//
//  Created by dllo on 15/10/27.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ActivityDetailView.h"
#import "AllMovieDetailView.h"
#import "UIImageView+WebCache.h"

@interface ActivityDetailView ()

@property (nonatomic, retain)UILabel *titleL;
@property (nonatomic, retain) UILabel *time;
@property (nonatomic, retain) UILabel *owner;
@property (nonatomic, retain) UILabel *category;
@property (nonatomic, retain) UILabel *categoryL;
@property (nonatomic, retain) UILabel *address;
@property (nonatomic, retain) UIImageView *activityImageV;
@property (nonatomic, retain) UIImageView *titleImageV;
@property (nonatomic, retain) UIImageView *timeImageV;
@property (nonatomic, retain) UIImageView *ownerImageV;
@property (nonatomic, retain) UIImageView *categoryImageV;
@property (nonatomic, retain) UIImageView *addressImageV;

@property (nonatomic, retain) UILabel *activityIntroduce;
@property (nonatomic, retain) UILabel *content;
@property (nonatomic, retain) UIScrollView *scrollV;



@end

@implementation ActivityDetailView


- (void)dealloc
{
    [_scrollV release];
    [_content release];
    [_activity release];
    [_titleL release];
    [_time release];
    [_owner release];
    [_category release];
    [_address release];
    [_activityImageV release];
    [_titleImageV release];
    [_timeImageV release];
    [_ownerImageV release];
    [_categoryImageV release];
    [_addressImageV release];
    [_activityIntroduce release];

}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    
    return self;
}

- (void)createSubviews
{
    
    self.scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 414, 736 - 64 - 49)];
    self.scrollV.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.scrollV];
    [_scrollV release];
    
    
    //核心属性,能够滚动的属性
    //真正动的是scrollV下的contentview
    
    //左右滑动
    
    //scrollV.contentSize = CGSizeMake(self.frame.size.width, 1200);
    
    
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, self.frame.size.width - 40, 30)];
    //self.titleL.backgroundColor = [UIColor orangeColor];
    //self.titleL.text = @"罗马与巴洛克艺术";
    self.titleL.font = [UIFont boldSystemFontOfSize:18.0];
    [self.scrollV addSubview:self.titleL];
    [_titleL release];
    
    self.activityImageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, self.titleL.frame.origin.y + self.titleL.frame.size.height + 10, 110, 160)];
    self.activityImageV.image = [UIImage imageNamed:@"picholder.png"];
    //self.activityImageV.backgroundColor = [UIColor grayColor];
    [self.scrollV addSubview:self.activityImageV];
    [_activityImageV release];
    
    self.timeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.activityImageV.frame.origin.x + self.activityImageV.frame.size.width + 10, self.activityImageV.frame.origin.y + 5, 20, 20)];
    self.timeImageV.image = [UIImage imageNamed:@"icon_date_blue.png"];
    //self.timeImageV.backgroundColor = [UIColor orangeColor];
    [self.scrollV addSubview:self.timeImageV];
    [_timeImageV release];
    
    self.ownerImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.timeImageV.frame.origin.x, self.timeImageV.frame.origin.y + self.timeImageV.frame.size.height + 10, 20, 20)];
    self.ownerImageV.image = [UIImage imageNamed:@"icon_sponsor_blue@2x.png"];
    //self.ownerImageV.backgroundColor = [UIColor orangeColor];
    [self.scrollV addSubview:self.ownerImageV];
    [_ownerImageV release];
    
    self.categoryImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.ownerImageV.frame.origin.x, self.ownerImageV.frame.origin.y + self.ownerImageV.frame.size.height + 10, 20, 20)];
    self.categoryImageV.image = [UIImage imageNamed:@"icon_catalog_blue.png"];
    //self.categoryImageV.backgroundColor = [UIColor orangeColor];
    [self.scrollV addSubview:self.categoryImageV];
    [_categoryImageV release];
    
    
    self.addressImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.categoryImageV.frame.origin.x, self.categoryImageV.frame.origin.y + self.categoryImageV.frame.size.height + 10, 20, 20)];
    self.addressImageV.image = [UIImage imageNamed:@"icon_spot_blue.png"];
    //self.addressImageV.backgroundColor = [UIColor orangeColor];
    [self.scrollV addSubview:self.addressImageV];
    [_addressImageV release];
    
    
    self.time = [[UILabel alloc] initWithFrame:CGRectMake(self.timeImageV.frame.origin.x + self.timeImageV.frame.size.width + 5, self.timeImageV.frame.origin.y, self.frame.size.width - 20 * 2 - self.activityImageV.frame.size.width - 10 - self.timeImageV.frame.size.width - 5, 20)];
    //self.time.text = @"07-22 09:00 - 10-16 17:00";
    //self.time.backgroundColor = [UIColor grayColor];
    [self.scrollV addSubview:self.time];
    [_time release];
    
    
    self.owner = [[UILabel alloc] initWithFrame:CGRectMake(self.timeImageV.frame.origin.x + self.timeImageV.frame.size.width + 5, self.time.frame.origin.y + self.time.frame.size.height + 10, self.frame.size.width - 20 * 2 - self.activityImageV.frame.size.width - 10 - self.timeImageV.frame.size.width - 5, 20)];
    //self.owner.text = @"国家博物馆";
    //self.owner.backgroundColor = [UIColor grayColor];
    [self.scrollV addSubview:self.owner];
    [_owner release];
    
    
    self.category = [[UILabel alloc] initWithFrame:CGRectMake(self.timeImageV.frame.origin.x + self.timeImageV.frame.size.width + 5, self.owner.frame.origin.y + self.owner.frame.size.height + 10, 40, 20)];
    self.category.text = @"类型:";
    //self.category.backgroundColor = [UIColor grayColor];
    [self.scrollV addSubview:self.category];
    [_category release];
    
    self.categoryL = [[UILabel alloc] initWithFrame:CGRectMake(self.category.frame.origin.x + self.category.frame.size.width + 10, self.owner.frame.origin.y + self.owner.frame.size.height + 10, self.frame.size.width - 20 * 2 - self.activityImageV.frame.size.width - 10 - self.timeImageV.frame.size.width - 55, 20)];
    //self.categoryL.text = @"展览";
    //self.category.backgroundColor = [UIColor grayColor];
    [self.scrollV addSubview:self.categoryL];
    [_categoryL release];
    
    
    self.address = [[UILabel alloc] initWithFrame:CGRectMake(self.timeImageV.frame.origin.x + self.timeImageV.frame.size.width + 5, self.category.frame.origin.y + self.category.frame.size.height + 10, 220, 20)];
    //self.address.text = @"北京 东城区 东长安街16号中国国家博物馆";
//    self.address.numberOfLines = 0;
//    [self.address sizeToFit];
    //self.address.backgroundColor = [UIColor grayColor];
    [self.scrollV addSubview:self.address];
    [_address release];
    
    
    
    self.activityIntroduce = [[UILabel alloc] initWithFrame:CGRectMake(20, self.activityImageV.frame.origin.y + self.activityImageV.frame.size.height + 10, 90, 30)];
    //self.activityIntroduce.backgroundColor = [UIColor grayColor];
    self.activityIntroduce.text = @"活动介绍";
    self.activityIntroduce.font = [UIFont boldSystemFontOfSize:21.0];
    [self.scrollV addSubview:self.activityIntroduce];
    [_activityIntroduce release];
    
    
    self.content = [[UILabel alloc] initWithFrame:CGRectMake(20, self.activityIntroduce.frame.origin.y + self.activityIntroduce.frame.size.height + 10, self.frame.size.width - 40, 20)];
//    self.content.numberOfLines = 0;
//    [self.content sizeToFit];
    //self.content.backgroundColor = [UIColor redColor];
    [self.scrollV addSubview:self.content];
    [_content release];

    NSLog(@"活动简介的坐标y = %f", self.activityImageV.frame.origin.y + self.activityImageV.frame.size.height + 10);
    
}



- (void)setActivity:(Activity *)activity
{
    if (_activity != activity) {
        [_activity release];
        _activity = [activity retain];
    }
    
    NSURL *url = [NSURL URLWithString:self.activity.image];
    [self.activityImageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"picholder.png"]];
    
    self.titleL.text = self.activity.title;
    
    NSRange range = {5, 11};
    NSString *str1 = [[self.activity.begin_time substringWithRange:range] stringByAppendingString:@"--"];
    NSString *str2 = [self.activity.end_time substringWithRange:range];
    NSString *str = [str1 stringByAppendingString:str2];
    self.time.text = str;//@"07-22 09:00 - 10-16 17:00";
    
    self.owner.text = self.activity.name;//@"国家博物馆";
    
    self.categoryL.text = self.activity.category_name;//@"展览";
    
    self.address.text = self.activity.address;//@"北京 东城区 东长安街16号中国国家博物馆";
    self.address.numberOfLines = 0;
    [self.address sizeToFit];
 
    self.content.text = self.activity.content;//@"kdfjkdf";
    CGFloat height = [AllMovieDetailView heightForContent:self.activity.content width:414 - 40];
    CGRect frame = self.content.frame;
    frame.size.width = 414 - 40;
    frame.size.height = height;
    self.content.frame = frame;
    self.content.numberOfLines = 0;
    [self.content sizeToFit];
    
    NSLog(@"%f", height);
    
    //自定义scrollV高度
//    CGFloat height = [AllMovieDetailView heightForContent:self.activity.content width:414 - 40];
    //self.scrollV.backgroundColor = [UIColor orangeColor];
    CGFloat height1 = [AllMovieDetailView heightForContent:self.activity.content width:414];
    self.scrollV.contentSize = CGSizeMake(414, height1 + 120);
    }







/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
